/* Copyright (C) 2011. ChengDu Unicon system, All Rights Reserved */

/*""FILE COMMENT""******************************* Technical reference data ****
* File Name	: cam_a.asm
* Version 	: 1.00
* Device 	: SH72543
* Tool Chain 	: 
* H/W Platform	: 
* Description 	: 
******************************************************************************/

/******************************************************************************
* History 	: 09.08.2011 Ver. 1.00 First Release
*		: 
*FILE COMMENT END*********************************************************/
        #include    "os_cpu_a.inc"
  
        PUBLIC     _CamMeasureISR
        EXTERN     _OSTCBCur
        EXTERN     _OSPrioCur
        EXTERN     _OSPrioHighRdy
        EXTERN     _OSIntEnter
        EXTERN     _OSTimeTick
        EXTERN     _OSIntExit
        EXTERN     _OSIntNesting
        EXTERN     _CamMeasureISRHandler
        
        SECTION    __DEFAULT_CODE_SECTION__:CODE:NOROOT(2)
;********************************************************************************************************
;                                                CamMeasureISR()
;********************************************************************************************************
_CamMeasureISR:       
        OS_CTX_SAVE                         ; save processor registers on the stack

        mov.l   #_OSIntNesting, r1          ; Load BN to OSIntNesting
        mov.l   #IBNR, r2                   ; 
        mov.w   @r2, r0
        extu.b  r0, r0
        mov.b   r0, @r1                     ; If OSIntNesting == 1 save the current stack pointer              
        tst     #1, r0                      ; onto the current task's stack
        bt      _CamMeasureISR1

        mov.l   #_OSTCBCur, r1              ; Save current task's SP into its TCB
        mov.l   @r1, r0
        mov.l   r15, @r0        
        
_CamMeasureISR1:        
        RESBANK                             ; Restoring from Bank, BN-1
        mov.l   #_CamMeasureISRHandler, r0
        jsr     @r0                         ; call CamMeasureISRHandler()
        nop
        
        mov.l   #_OSIntExit, r0
        jsr     @r0                         ; call OSIntExit()
        nop

        OS_CTX_RESTORE                      ; restore all processor registers from stack
        
        rte
        nop
        END